package com.hf.lookatme.zview.fragments;

import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hf.lookatme.R;
import com.hf.lookatme.commons.CommonMethod;
import com.hf.lookatme.utils.ImageLoaderConfigUtils;
import com.hf.lookatme.zpresenter.Presenter_Fragment_Me;
import com.hf.lookatme.zview.activitys.Activity_GuessYourLike;
import com.hf.lookatme.zview.interfaces.IView_Fragment_Me;
import com.nostra13.universalimageloader.core.ImageLoader;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by JoeShiguang on 2015/5/15.
 */
public class Fragment_Me extends Fragment implements IView_Fragment_Me {

  private static final String TAG = "Fragment_Me";

  private Context context;

  private View view_fragment;

  private ImageLoader imageLoader;

  private Presenter_Fragment_Me presenter;


  @InjectView(R.id.textView_fragment_me_userName)
  TextView textView_userName;

  @InjectView(R.id.textView_fragment_me_userLocation)
  TextView textView_userLocation;

  @InjectView(R.id.imageView_fragment_me_headImg)
  ImageView imageView_userHeadImg;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    context = getActivity();
    presenter = new Presenter_Fragment_Me(this);
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    try {
      view_fragment = inflater.inflate(R.layout.fragment_me, container, false);
      ButterKnife.inject(this, view_fragment);
      //imageLoader = ImageLoaderConfigUtils.instanceImageLoader(context);

      //加载用户头像
      String imageUri = "drawable://" + R.drawable.img_mr;
      //imageLoader.displayImage(imageUri, imageView_userHeadImg, ImageLoaderConfigUtils.createDisplayHeadImageOptions());
      imageView_userHeadImg.setImageResource(R.drawable.img_mr_round);
      //加载用户位置信息
      presenter.getLocationInfo(context);

    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return view_fragment;
  }

  @OnClick(R.id.linearLayout_fragment_me_guessYourLike)
  void onLayout_guessYourLikeClicked(View view){
    if(CommonMethod.isFastDoubleClick()){
      return;
    }
    Intent intent = new Intent();
    intent.setClass(context, Activity_GuessYourLike.class);
    context.startActivity(intent);
  }


  @Override
  public void setUserHeadImg(String imgPath) {

    imageLoader.displayImage(imgPath, imageView_userHeadImg, ImageLoaderConfigUtils.createDisplayHeadImageOptions());
  }

  @Override
  public void setUserName(String userName) {

    textView_userName.setText(userName);
  }

  @Override
  public void setUserLocation(String location) {

    if (location != null && location.length() > 0) {

      textView_userLocation.setText(location);
    }
  }
}
